package com.qezhhnjy.cloud.rabbitmq;

import com.qezhhnjy.cloud.rabbitmq.demo.Producer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author zhaoyangfu - 2020/7/31 15:21
 */
@SpringBootApplication
public class RabbitApp implements CommandLineRunner {

    @Resource
    private Producer producer;

    public static void main(String[] args) {
        SpringApplication.run(RabbitApp.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            while (!Thread.interrupted()) {
                demo();
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    /** 简易实现rabbitmq的生产和消费 */
    public void demo() {
        producer.produce();
    }
}
